#============================================================================
#Name        : Makefile
#Author      : Chris Meaclem, Chris McPherson, Andrew, Isaac
#Date        : 30/07/2011
#Version     : Intermediate
#Description : Derived from soruce by Dr M. Hayes. UC ECE
#============================================================================

# Definitions.
CC = avr-gcc
CFLAGS = -mmcu=atmega8 -Os -Wall -Wstrict-prototypes -W -g -I../../avr_hal -I../../common -I.
OBJCOPY = avr-objcopy
SIZE = avr-size
DEL = rm


# Search directories for files.
VPATH = ../../avr_hal ../../common


# Default target.
all: main.hex


# Compile: create object files from C source files.
main.o: main.c config.h target.h pacer.h tinygl.h display.h ../fonts/font5x7_1.h font.h boing.h
	$(CC) -c $(CFLAGS) $< -o $@

pacer.o: pacer.c config.h target.h pacer.h
	$(CC) -c $(CFLAGS) $< -o $@

tinygl.o: tinygl.c tinygl.h config.h target.h display.h ../fonts/font5x7_1.h font.h pacer.h
	$(CC) -c $(CFLAGS) $< -o $@

display.o: display.c ledmat.h config.h target.h display.h
	$(CC) -c $(CFLAGS) $< -o $@

boing.o: boing.c boing.h tinygl.h config.h target.h display.h ../fonts/font5x7_1.h font.h pacer.h
	$(CC) -c $(CFLAGS) $< -o $@

ledmat.o: ledmat.c pio.h config.h target.h ledmat.h
	$(CC) -c $(CFLAGS) $< -o $@

pio.o: pio.c
	$(CC) -c $(CFLAGS) $< -o $@

#pongModule.o: pongModule.c pongModule.h
	$(CC) -c $(CFLAGS) $< -o $@

# Link: create ELF output file from object files.
main.out: main.o pacer.o tinygl.o display.o boing.o ledmat.o pio.o
	$(CC) $(CFLAGS) $^ -o $@
	$(SIZE) $@


# Create hex output file from ELF output file.
main.hex: main.out
	$(OBJCOPY) -O ihex main.out main.hex


# Target: clean project.
.PHONY: clean
clean:
	-$(DEL) *.o *.out *.hex

.PHONY: realclean
realclean: clean	
	-$(DEL) *~ *.bak


# Target: program project.
.PHONY: program
program: main.hex
	cp $^ /tmp/
	-bootloadHID -r /tmp/$^
	$(DEL) /tmp/$^

